<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" top="0" width="480px" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px">
			<el-form-item label="名单名称" prop="name">
				<el-input v-model="formData.name"></el-input>
			</el-form-item>
			<el-form-item label="名单类型" prop="type">
				<el-radio-group v-model="formData.type">
					<el-radio label="1">黑名单</el-radio>
					<el-radio label="2">白名单</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="IP地址" prop="ipAddr">
				<sw-ip-input placeholder="请输入IP地址" v-model="formData.ipAddr" size="medium" style="width: 200px"></sw-ip-input>
			</el-form-item>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm">{{ addOrEdit ? '新增' : '修改' }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '@/mixins/formMixins';
import { blackDetail, addedBlack, updateBlack } from '@/api/system/tbSysBlack';
export default {
	mixins: [formMixins],
	props: {
		type: { type: String, default: '' }
	},
	data() {
		return {
			formName: '名单',
			visible: this.value,
			formRules: {
				name: [{ required: true, message: '请输入名单名称', trigger: 'blur' }],
				ipAddr: [{ required: true, message: '请输入IP地址', trigger: 'blur' }]
			},
			btnLoading: false
		};
	},
	computed: {
		detailData() {
			return eval(blackDetail);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedBlack : updateBlack);
		}
	},
	methods: {
		formatFormParams(data) {
			if (this.addOrEdit) {
				this.$set(data, 'type', this.type);
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.role_form_wrapper {
	width: 100%;
	padding: 10px 6px 0 0;
	box-sizing: border-box;
}
</style>
